<?php


namespace Modules\Common\Helpers\Traits\Models;


use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;

trait Scope {

    public function scopeCreatedAtOfDay(Builder $query, $data) {
        return $query->whereBetween('created_at', [Carbon::parse($data)->startOfDay(), Carbon::parse($data)->endOfDay()]);
    }
    public function scopeUpdatedAtOfDay(Builder $query, $data) {
        return $query->whereBetween('updated_at', [Carbon::parse($data)->startOfDay(), Carbon::parse($data)->endOfDay()]);
    }
    public function scopeReviewAtOfDay(Builder $query, $data) {
        return $query->whereBetween('review_at', [Carbon::parse($data)->startOfDay(), Carbon::parse($data)->endOfDay()]);
    }

    public function scopeServiceTimeBefore(Builder $query, $date): Builder {
        return $query->where('service_time', '<=', Carbon::parse($date));
    }

    public function scopeServiceTimeAfter(Builder $query, $date): Builder {
        return $query->where('service_time', '>=', Carbon::parse($date));
    }

    public function scopeServiceTimeBetween(Builder $query, $start, $end): Builder {

        return $query->whereBetween('service_time', [$start, $end]);
    }


    public function scopeCreatedAtBefore(Builder $query, $date): Builder {
        return $query->where('created_at', '<=', Carbon::parse($date));
    }

    public function scopeCreatedAtAfter(Builder $query, $date): Builder {
        return $query->where('created_at', '>=', Carbon::parse($date));
    }

    public function scopeCreatedAtBetween(Builder $query, $start, $end): Builder {

        return $query->whereBetween('created_at', [$start, $end]);
    }

    public function scopeUpdatedAtBefore(Builder $query, $date): Builder {
        return $query->where('updated_at', '<=', Carbon::parse($date));
    }

    public function scopeUpdatedAtAfter(Builder $query, $date): Builder {
        return $query->where('updated_at', '>=', Carbon::parse($date));
    }

    public function scopeUpdatedAtBetween(Builder $query, $start, $end): Builder {
        return $query->whereBetween('updated_at', [$start, $end]);
    }


}
